<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/vue@next"></script>

</head>

<body>
  <div id="app">
    <fa></fa>

  </div>

</body>
<script>

  // provide(供应) & inject(注入)

  const app = Vue.createApp({})

  app.component('fa', {
    template: `<div> <c1 /><h1>{{c}}</h1><button @click="c=555">我是fa</button></div>`,
    data() {
      return {
        c: 123
      }
    },
    // 如果希望provide访问到组件内部的属性 如data里面的内容 要把provide
    // 转换成一个函数返回一个对象
    provide() {
      return {
        name: this.c

      }
    }
  })

  app.component('c1', {
    template: `
          <div>
              <d1 />
          </div>
    `,
    provide: {
      dd: 'hi gril'
    }
  })

  app.component('d1', {
    template: `
        <div>
            {{name}} {{dd}}
        </div>
    `,
    inject: ['name', 'dd']
  })

  app.mount('#app')
</script>

</html>